package com.zyh.kafka.util;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.serialization.StringSerializer;

import java.util.Properties;

public class KafkaProducerUtils {
    //1。提供生产者需要的配置参数
    private static Properties producerConfigs = new Properties();

    public static KafkaProducer<String,String> get(){
        producerConfigs.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"kafka24:9092");
        producerConfigs.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer .class.getName());
        producerConfigs.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,StringSerializer.class.getName());
        return new KafkaProducer<>(producerConfigs);
    }

    public static void close(KafkaProducer<String,String> producer){
        producer.close();
    }
}
